package semant.second_pass;

import util.List;
import semant.Env;
import symbol.Symbol;
import symbol.ClassInfo;
import syntaxtree.ClassDecl;
import syntaxtree.ClassDeclSimple;
import syntaxtree.ClassDeclExtends;
import syntaxtree.MethodDecl;
import syntaxtree.VarDecl;
import syntaxtree.VisitorAdapter;

final class ClassDeclHandler extends VisitorAdapter {

    private Env env;

    private ClassDeclHandler(Env e){
	super();
	env = e;
    }

    static void secondPass(Env e, ClassDecl cd){
	ClassDeclHandler h = new ClassDeclHandler(e);
	cd.accept(h);
    }

    public void visit(ClassDecl node){
	ClassInfo cinfo = env.classes.get(Symbol.symbol(node.name.s));

	// verifica atributos da classe
	for(List<VarDecl> vd = node.varList; vd != null; vd = vd.tail)
	    VarDeclHandler.secondPass(env, vd.head);

	// verifica os metodos
	for(List<MethodDecl> md = node.methodList; md != null; md = md.tail)
	    MethodDeclHandler.secondPass(env, cinfo, md.head);
    }

    public void visit(ClassDeclSimple node){
	visit((ClassDecl)node);
    }

    public void visit(ClassDeclExtends node){
	visit((ClassDecl)node);
    }

}
